package org.leon.service.impl;

import org.leon.dao.ResumeDao;
import org.leon.pojo.Resume;
import org.leon.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Optional;


@Service
public class ResumeServiceImpl implements ResumeService {

    private ResumeDao resumeDao;

    @Autowired
    public ResumeServiceImpl(ResumeDao resumeDao) {
        this.resumeDao = resumeDao;
    }

    @Override
    public List<Resume> queryAll() {
        return resumeDao.findAll();
    }

    @Override
    public void createResume(Resume resume) {

    }

    @Override
    public void editResume(Resume resume) {
        if (StringUtils.isEmpty(resume.getName())) {
            resume.setName("-");
        }
        if (StringUtils.isEmpty(resume.getPhone())) {
            resume.setPhone("-");
        }
        if (StringUtils.isEmpty(resume.getAddress())) {
            resume.setAddress("-");
        }

        resumeDao.save(resume);
    }

    @Override
    public void deleteResumeById(Integer rId) {
        resumeDao.deleteById(rId);
    }

    @Override
    public Optional<Resume> findById(Integer id) {
        return resumeDao.findById(id);
    }

}
